<!DOCTYPE html>
<html>
  <head>
  	<div th:include="base-libs :: base-libs" />
    <title>号源规则设置-新增/修改</title>
	
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
    
    <style>
    	.hidden{
    		display:none;
    	}
    	.combo{
    		width:90% !important
    	}
    	.validatebox-text{
    		width:100% !important;
    	}
    	.boxs{
    		position:relative;
    	}
    	.inTitle{
    		color:red;
    		background:#fff;
    		position:absolute;
    		top:-10px;
    		left:10px;
    		font-size:14px;
    		padding:0 5px;
    	}
    </style>
    
    <script th:inline="javascript">
	    /**读取request中的初始化数据*/
	    var requestData = [[${requestData}]];
	</script>
	<script>
		$(function(){
            $(this).registerManagerPage();
			initView();
			initData();
		})
		
		function initView(){
			//保存
			$("#btnBc").click(function(){
				if($(".form-control").QuickValidate()){
					if(parseInt($("#KYYTS").val()) < parseInt($("#YSTS").val())){
						var errMsg = '<span style="color:red">优势天数</span>不能大于<span style="color:red">可预约天数</span>！';
						$.QuickAlert.alertFail({content: errMsg});
					}else{
						$.QuickRemote.AjaxFiledFormSubmit("hygzszForm", saveHandler, {GXYH: parent.userInfo.USERID});
					}
				}
			})
			
			//返回
			$("#btnFh").click(function(){
				$.QuickUrlUtils.redirectUrl("index.html");
			})
			
			/** 医疗机构combogrid */
			var readonly = !requestData["isManager"];
			$("#combogridYljg").combogrid({
	            height: 30
	            ,width: 300
	            ,panelWidth: 700
	            ,singleSelect: true
	            ,pagination: true
	            ,idField: 'PTJGID'
	            ,textField: 'YLJGMC'
	            ,mode: "remote"
	            ,readonly: readonly
	            ,hasDownArrow: !readonly
	            ,url: "/console/yljgxx/queryPageSummary.service"
	            ,delay: 1000
	            ,reversed: false
	            ,fitColumns: true
	            ,columns:[[
	                {field:'YLJGMC',title:'机构名称',width:240},
	                {field:'XZQHMC',title:'行政区划',width:80},
	                {field:'WSJGLBMC',title:'机构类别',width:80},
	                {field:'YYDJMC',title:'机构等级',width:80}
	            ]]
	            ,onBeforeLoad: function(queryParams) {
	                var url = $(this).datagrid("options")["url"];
					/*URL不等空时再发送请求*/
	                if (!readonly) {
	                    queryParams["pageSize"] = queryParams["rows"];
	                    queryParams["pageNumber"] = queryParams["page"];
	                    queryParams["YLJGMC"] = queryParams["q"];
	                    var result = [];
	                    $("#YJKSDM").createOptions(result,{textField : "KSMC" , valueField : "KSDM"});
	                    return true;
	                }else{
	                    return false;
	                }
	            },
	            onClickRow : function(rowIndex, rowData){
	            	initKsxx(rowData);
	            },
	            onLoadSuccess : function(data){

				}
	        });
			
			//点击input展开combogrid
			$(".validatebox-text").click(function(){
				$('.combo-arrow').trigger('click');
			})
			
			$("#YSTS,#KYYTS").blur(function(){
				var KYYTS = parseInt($("#KYYTS").val());
				var YSTS = parseInt($("#YSTS").val());
				var result;
				if(KYYTS && YSTS){
					result = KYYTS - YSTS;
					if(result<0){
						result = 0;
						var errMsg = '<span style="color:red">优势天数</span>不能大于<span style="color:red">可预约天数</span>！';
						$.QuickAlert.alertFail({content: errMsg});
					}
				}
				$("#PTTS").val(result);
			})
		}
		
		function initData(){
			var hygzglData = StoreCache.removeCache("hygzglData");
			if(!$.isEmptyObject(hygzglData)){
				$("#combogridYljg").combogrid("setValue", hygzglData);
				initKsxx(hygzglData);
				$("#type").val('update');
				$(".form-control").each(function(){
					var name = $(this).attr('name');
					$(this).val(hygzglData[name]);
				})

				$("[name=SFYSHY]").eq(hygzglData.SFYSHY).prop("checked","checked");
			}else if(!requestData["isManager"]){
			    var jgxx = {PTJGID: parent.userInfo.PTJGID, YLJGMC: parent.userInfo.YLJGMC}
                $("#combogridYljg").combogrid("setValue", jgxx);
                initKsxx(jgxx);
			}
			
			//是否优势号源
			$("[name=SFYSHY]:checked").trigger("click");
		}
		
		/** 保存回调 */
		function saveHandler(result){
			if(result.state){
				$.QuickAlert.alertNormal(result.info, {callback: function(){
					$("#btnFh").trigger("click");
				}});
			}else{
				$.QuickAlert.alertFail({content: result.info});
			}
		}
		
		/** 初始化一级科室下拉框 */
		function initKsxx(params2){
			var params = $.extend({},params2);//处理乱码
			$("#YLJGDM").val(params.YLJGDM);
			$("#YLJGMC").val(params.YLJGMC);
			$("#PTJGID").val(params.PTJGID);
	        $.QuickRemote.AjaxJson("/console/ksxx/", function(result){
	            $("#KSDM").createOptions(result,{textField : "KSMC" , valueField : "KSDM"});
	            $("#KSDM").val(params.KSDM);
	        }, params);
		}
		
		/** 修改是否优势号源 */
		function boxsSet(isYes){
			if(!isYes){
				//否
				$(".boxs")
					.find('span:not(.quick-not-null)').css({'color':'#ddd'}).end()
					.find('.td-text,span:not(.quick-not-null)').css({'background':'#fff','color':'#ddd'}).end()
					.find('input:not([name=KHDXLX]),select').val('').attr('disabled','disabled')
						.css({color: '#ddd',borderColor:'#ddd'}).removeClass('form-control').end()
					.find('[name=KHDXLX]').attr('disabled','disabled');
			}else{
				//是
				$(".boxs")
					.find('span:not(.quick-not-null)').css({'color':'#666'}).end()
					.find('.td-text').css({'background':'#f7f9fb','color':'#666'}).end()
					.find('input:not([name=KHDXLX]),select').removeAttr('disabled')
						.css({color: '#333',borderColor:'#B6B6B6'}).addClass('form-control').end()
					.find('[name=KHDXLX]').removeAttr('disabled');
			}
		}
	</script>
  </head>
  
  <body class="easyui-layout">
    <div region="center">
    	<h4 class="h4-title" style="text-align:left;margin:0;padding-left:15px;font-size: 18px;">
			添加号源规则
		</h4>
		<form action="save" id="hygzszForm">
			<input id="type" name="type" value="add" class="hidden"/>
			<input name="GZBH" class="form-control hidden" />
			<input name="ZT" class="form-control hidden" value="1"/>


			<div class="easyui-panel" style="height: 198px;overflow:hidden" title="号源基本信息">
				<table class="form-table">
					<tr>
						<td class="td-text"><label>规则名称：</label></td>
						<td class="td-content">
							<input name="GZMC" class="form-control"
							quick-config="label:'规则名称', validateProxy:'notNull length', length:'128'"/>
						</td>
					</tr>
					<tr>
						<td class="td-text"><label>医院名称：</label></td>
						<td class="td-content">
							<input id="combogridYljg" />
							<input id="PTJGID" name="PTJGID" class="form-control hidden" quick-config="label:'医院名称', validateProxy:'notNull'"/>
							<input id="YLJGDM" name="YLJGDM" class="form-control hidden"/>
							<input id="YLJGMC" name="YLJGMC" class="form-control hidden"/>
						</td>
					</tr>
					<tr>
						<td class="td-text"><label>可预约天数：</label></td>
						<td class="td-content">
							<input id="KYYTS" name="KYYTS" class="form-control"
							quick-config="label:'可预约天数', validateProxy:'notNull length num', length:'5'"/>
						</td>
					</tr>
					<tr>
						<td class="td-text"><label>享有优势号源：</label></td>
						<td class="td-content">
							<input onclick="boxsSet(false)" style="width:18px;float:left" type="radio" name="SFYSHY" value="0" />
							<span style="float:left;margin-right:15px">否</span>
							<input onclick="boxsSet(true)" style="width:18px;float:left" type="radio" name="SFYSHY" value="1" checked="checked">
							<span style="float:left;">是</span>

						</td>
					</tr>
				</table>
			</div>
			<div class="easyui-panel " style="height: 155px;overflow:hidden" title="控号规则设置">
				<table class="form-table boxs">
					<tr>
						<td class="td-text"><label>控号比例(%)：</label></td>
						<td class="td-content">
							<input name="KHBL" class="form-control"
							quick-config="label:'控号比例', validateProxy:'notNull length', length:'3'"/>
						</td>
					</tr>
					<tr>
						<td class="td-text"><label>控号对象类型：</label></td>
						<td class="td-content">
							<input class="form-control" style="width:18px;float:left" type="radio" name="KHDXLX" value="01" checked="checked"/>
							<span style="float:left;margin-right:15px">科室</span>
						</td>
					</tr>
					<tr>
						<td class="td-text"><label>科室名称：</label></td>
						<td class="td-content">
							<select id="KSDM" name="KSDM" class="form-control" style="width:90.3%">
								<!--quick-config="label:'科室名称', validateProxy:'notNull'"-->
								<option value="">请选择</option>
							</select>
							
							<input id="KSMC" name="KSMC" class="form-control hidden"/>
						</td>
					</tr>
				</table>
			</div>
			<div class="easyui-panel" style="height: 120px;" title="时间规则设置">
				<table class="form-table boxs">
					<tr>
						<td class="td-text"><label>优势天数：</label></td>
						<td class="td-content">
							<input id="YSTS" name="YSTS" class="form-control"
							quick-config="label:'优势天数', validateProxy:'notNull length num', length:'5'"/>
						</td>
					</tr>
					<tr>
						<td class="td-text"><label>普通天数：</label></td>
						<td class="td-content">
							<input id="PTTS" name="PTTS" class="form-control" readonly="readonly" />
						</td>
					</tr>
				</table>
			</div>
		</form>
    </div>
    
    <div region="south" style="height:50px;line-height:50px;text-align:center;overflow:hidden;border:0;border-top:1px solid #ddd">
    	<button id="btnBc" class="btn btn-info" type="button">保存</button>
    	<button id="btnFh" class="btn btn-info" type="button">返回</button>
    </div>
  </body>
</html>
